package com.lhnstart.learn.bases.collection_.list_;

import lombok.*;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * 排序后遍历集合
 *
 * @author lhn
 * @date 2023/10/31 20:23
 * @since 1.0.0
 **/
public class ListExercise02 {

    @SuppressWarnings({"all"})
    public static void main(String[] args) {
        ArrayList <Book> list = new ArrayList <>();
        list.add(new Book("红楼梦", "曹雪芹", 59));
        list.add(new Book("西游记", "吴承恩", 39));
        list.add(new Book("三国演义", "罗黄忠", 29));
        list.add(new Book("水浒传", "施耐庵", 99));
        for (int i = 0; i < list.size()-1; i++) {
            for (int j = 0; j < list.size() - 1 - i; j++) {
                if (list.get(i).getPrice() < list.get(j).getPrice()) {
                    Book tramp = list.get(i);
                    list.set(i, list.get(j));
                    list.set(j, tramp);
                }
            }
        }
        Iterator <Book> iterator = list.iterator();
        while (iterator.hasNext()) {
            Book next = iterator.next();
            System.out.println("next = " + next);
        }
    }

}

@Data
@NoArgsConstructor
@AllArgsConstructor
@ToString
class Book {
    /** name */
    private String name;

    private String author;

    /**  price */
    private Integer price;

}